package com.css.apps.base.user.action.report;

import java.util.ArrayList;
import java.util.List;

import com.css.apps.base.common.Constants;
import com.css.webbase.webwork.action.UserAction;
import com.css.apps.base.user.service.UserCountGraphService;
import com.css.util.ListUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class DirUserStatusCount extends UserAction {

	private transient UserCountGraphService service = new UserCountGraphService();
	private List<String> headerTab = new ArrayList<>(), subTab = new ArrayList<>();
	private List<Object> headerData = new ArrayList<>(), subData = new ArrayList<>();
	private JSONArray headerLegend = new JSONArray(), subLegend = new JSONArray();
	private JSONArray headerChartData = new JSONArray(), subChartData = new JSONArray();
	
	@Override
	protected String userGo() {
		initTabHeader();
		List<Object[]> headerCount = service.getHeaderUserStatusCountTabData();
		if (ListUtil.isLstNotEmpty(headerCount)) {
			JSONObject hd = new JSONObject();
			for (Object[] hc : headerCount) {
				if (Constants.YES.equals(hc[1])) {
					headerData.add(0, hc[0]);
					hd.put("name", "使用中");
					hd.put("value", hc[0]);
				} else {
					headerData.add(hc[0]);
					hd.put("name", "停用");
					hd.put("value", hc[0]);
				}
				headerChartData.add(hd);
			}
		}
		List<Object[]> subOrgCount = service.getSubOrgUserStatusCountTabData();
		if (ListUtil.isLstNotEmpty(subOrgCount)) {
			JSONObject sd = new JSONObject();
			for (Object[] hc : subOrgCount) {
				if (Constants.YES.equals(hc[1])) {
					subData.add(0, hc[0]);
					sd.put("name", "使用中");
					sd.put("value", hc[0]);
				} else {
					subData.add(hc[0]);
					sd.put("name", "停用");
					sd.put("value", hc[0]);
				}
				subChartData.add(sd);
			}
		}
		
		return SUCCESS;
	}

	private void initTabHeader() {
		headerTab.add("使用中");
		headerTab.add("停用");
		headerLegend.add("使用中");
		headerLegend.add("停用");
		subTab.add("使用中");
		subTab.add("停用");
		subLegend.add("使用中");
		subLegend.add("停用");
	}

	public List<String> getHeaderTab() {
		return headerTab;
	}

	public void setHeaderTab(List<String> headerTab) {
		this.headerTab = headerTab;
	}

	public List<String> getSubTab() {
		return subTab;
	}

	public void setSubTab(List<String> subTab) {
		this.subTab = subTab;
	}

	public List<Object> getHeaderData() {
		return headerData;
	}

	public void setHeaderData(List<Object> headerData) {
		this.headerData = headerData;
	}

	public List<Object> getSubData() {
		return subData;
	}

	public void setSubData(List<Object> subData) {
		this.subData = subData;
	}

	public JSONArray getHeaderChartData() {
		return headerChartData;
	}

	public void setHeaderChartData(JSONArray headerChartData) {
		this.headerChartData = headerChartData;
	}

	public JSONArray getSubChartData() {
		return subChartData;
	}

	public void setSubChartData(JSONArray subChartData) {
		this.subChartData = subChartData;
	}

	public JSONArray getHeaderLegend() {
		return headerLegend;
	}

	public void setHeaderLegend(JSONArray headerLegend) {
		this.headerLegend = headerLegend;
	}

	public JSONArray getSubLegend() {
		return subLegend;
	}

	public void setSubLegend(JSONArray subLegend) {
		this.subLegend = subLegend;
	}

}
